//
//  CateTypeListViewController.swift
//  Spookiness
//
//  Created by 腾億 on 2017/12/13.
//  Copyright © 2017年 tml. All rights reserved.
//

import UIKit

class CateTypeListViewController: UIViewController {

    var pageContentView: SGPageContentView!
    var titleView:SGPageTitleView!
    var configure:SGPageTitleViewConfigure!
    
    var titleArr:[String]?
    var vcs: [UIViewController]?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
        navigationController?.navigationBar.setBackgroundImage(#imageLiteral(resourceName: "nav_bg").withColor(#colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)), for: .default)
        navigationController?.navigationBar.shadowImage = UIImage()
        
        
        setUpBarTitleView()
        // Do any additional setup after loading the view.
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        //导航栏按钮颜色
        navigationController?.navigationBar.tintColor = UIColor.black
        //导航栏字体颜色以及大小
        navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.black , NSAttributedStringKey.font: UIFont.systemFont(ofSize: 17)]
        UIApplication.shared.statusBarStyle = .default
    }
    
    convenience init(titleArr:[String], vcs:[UIViewController]) {
        self.init()
        self.titleArr = titleArr
        self.vcs = vcs
    }
    
    fileprivate func setUpBarTitleView() {
        configure = SGPageTitleViewConfigure.init()
        configure.titleColor = UIColor.black
        configure.titleSelectedColor = kRGBA(r: 127, g: 221, b: 146, a: 1)
        configure.indicatorScrollStyle = SGIndicatorScrollStyleHalf
        configure.indicatorColor = kRGBA(r: 127, g: 221, b: 146, a: 1)
        configure.titleFont = UIFont.systemFont(ofSize: 17)
        titleView = SGPageTitleView(frame: CGRect(x:0 , y:0 , width:self.view.width , height:kSCREEN_NAVBAR ), delegate: self, titleNames: titleArr, configure: configure)
        self.view.addSubview(titleView)
        titleView.isShowIndicator = true//指示器开启
        titleView.isOpenTitleTextZoom = false//关闭文字缩放效果
        titleView.isShowBottomSeparator = true//开启底部分割线
        titleView.isTitleGradientEffect = false//关闭文字有渐变效果
        let contentViewHeight =  self.view.height - 2*kSCREEN_NAVBAR - kSCREEN_STAUSBAR
        pageContentView = SGPageContentView(frame: CGRect(x:0 , y:kSCREEN_NAVBAR , width:self.view.width , height:contentViewHeight ), parentVC: self, childVCs: vcs)
        pageContentView.delegatePageContentView = self
        self.view.addSubview(pageContentView)
    }

}

extension CateTypeListViewController: SGPageContentViewDelegate {
    func pageContentView(_ pageContentView: SGPageContentView!, progress: CGFloat, originalIndex: Int, targetIndex: Int) {
        self.titleView.setPageTitleViewWithProgress(progress, originalIndex: originalIndex, targetIndex: targetIndex)
    }
}

extension CateTypeListViewController : SGPageTitleViewDelegate {
    func pageTitleView(_ pageTitleView: SGPageTitleView!, selectedIndex: Int) {
        
        self.pageContentView.setPageCententViewCurrentIndex(selectedIndex)
    }
    
    
}

